package com.zzjson.redis.redission;

import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * <p>****************************************************************************</p>
 * <li>Description : TODO </li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2021年03月02日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class RedissonBloomFilter {
	public static void main(String[] args) {
		Config config = new Config();
		config.useSingleServer().setAddress("redis://my-server:6377");
		//构造Redisson
		RedissonClient redisson = Redisson.create(config);

		RBloomFilter<String> bloomFilter = redisson.getBloomFilter("nameList");
		//初始化布隆过滤器：预计元素为100000000L,误差率为3%,根据这两个参数会计算出底层的bit数组大小
		bloomFilter.tryInit(100000L, 0.03);
		//将zhangsan插入到布隆过滤器中
		bloomFilter.add("zhangsan");
		bloomFilter.add("lisi");

		//判断下面号码是否在布隆过滤器中
		System.out.println(bloomFilter.contains("wangwu"));//false
		System.out.println(bloomFilter.contains("zhaoliu"));//false
		System.out.println(bloomFilter.contains("zhangsan"));//true
	}
}